<?php
$msg = $_REQUEST["msg"];
// echo "<h2>$msg</h2>";
// 数据格式验证
if(!isset($msg) || trim($msg) == "" ){
    echo "<h2>消息不能为空</h2>";
    return;
}
if(mb_strlen($msg) > 100){
    echo "<h2>消息的长度太长(不能超过100个字符)</h2>";
    return;
}

// 获取当前登录的用户
$loginUser = $_SESSION["loginUser"];
$userId = $loginUser["id"];
$conn = mysqli_connect("localhost:3306","root","","php");
$sql = "insert into t_msg (msg, send_user_id, send_date) values ('$msg', $userId, now())";
$result = mysqli_query($conn, $sql);
if($result){
    // 成功后, 跳转首页
    header("location:/week_homework/doCenter.php");
}
mysqli_close($conn);
?>